package com.tutu.rabbitmq.custome;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

/**
 * @Program: SpringBoot
 * @Description: 动态路由消费者
 * @Author: JK.TuTu
 * @Create: 2022-11-09 12:38
 **/
@Configuration
public class RouteTopicCustomer {

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue1"), //创建队列1
            exchange = @Exchange(name = "tutu.topic", type = ExchangeTypes.TOPIC),//交换机类型和名称
            key = "user.*"))   // *:只匹配一个单词  #:匹配0到多个单词
    public void directCustomer1(String message) {
        System.out.println("动态路由模式消费者1" + message);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("topic.queue2"), //创建队列1
            exchange = @Exchange(name = "tutu.topic", type = ExchangeTypes.TOPIC),//交换机类型和名称
            key = "user.#"))  // *:只匹配一个单词  #:匹配0到多个单词
    public void directCustomer2(String message) {
        System.out.println("动态路由模式消费者2" + message);
    }
}
